package danger.action.sys.dic;

import java.sql.SQLException;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;

import com.opensymphony.xwork2.ActionSupport;

import danger.service.sys.DictionaryService;
/**
 * 删除字典信息
 *
 */
@Component
public class DeleteDictionaryAction extends ActionSupport {

	private static final long serialVersionUID = -796150785473757381L;
	
	private String dictionaryIds;      //Ajax传过来的值（字典编号）
	private boolean result;

	@Resource
	private DictionaryService dictionaryService;
	
	public boolean getResult() {
		return result;
	}

	public void setResult(boolean result) {
		this.result = result;
	}

	public String getDictionaryIds() {
		return dictionaryIds;
	}

	public void setDictionaryIds(String dictionaryIds) {
		this.dictionaryIds = dictionaryIds;
	}

	/**
	 * 批量删除字典信息
	 * @return
	 */
	public String deleteDictionary() {
		//将得到的用户编号的字符串变为列表
		List<String> dictionaryIdList = java.util.Arrays.asList(dictionaryIds.split(","));
		this.result = true;
		//通过迭代达到批量删除用户的目的
		for(String dictionaryId:dictionaryIdList){
			try {
				this.result = this.result && dictionaryService.deleteDictionary(dictionaryId);
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		return SUCCESS;
	}
}